home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / SCSI Samples 1.0 / SCSI DriveID Sample 06⁄07 ƒ / Src / ShowRegisteredSCSIDevices.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-16  |  1.9 KB  |  86 lines  |  [TEXT/KAHL]

  1. /*                            ShowRegisteredSCSIDEvices.c                            */
  2. /*
  3.  * ShowRegisteredSCSIDEvices.c
  4.  * Copyright © 1992-94 Apple Computer Inc. All Rights Reserved.
  5.  *
  6.  * This subroutine prints the bus ID and driver refNum for all drivers
  7.  * registered with SCSI Manager 4.3
  8.  */
  9. #include <stdio.h>
  10. #include <Files.h>
  11. #include <Devices.h>
  12. #include <Memory.h>
  13. /*
  14.  * Include the O.S. files in a specific order to make sure that we have
  15.  * a definition for the _SCSIAtomic trap.
  16.  */
  17. #include <Traps.h>
  18. #ifndef _SCSIAtomic
  19. #define _SCSIAtomic    0xA089
  20. #endif
  21. /*
  22.  * Note that this uses a later version of <Scsi.h> than is available in
  23.  * the published headers.
  24.  */
  25. #include "Scsi.h"
  26.  
  27. Boolean                    AsyncSCSIPresent(void);
  28. void                    ShowRegisteredSCSIDevices(void);
  29.  
  30. static void
  31. ClearMemory(
  32.         Ptr                ptr,
  33.         Size            size
  34.     )
  35. {
  36.         while (size > 0) {
  37.             *ptr++ = 0;
  38.             --size;
  39.         }
  40. }
  41.  
  42.  
  43. void
  44. ShowRegisteredSCSIDevices(void)
  45. {
  46.         SCSIDriverPB            pb;
  47.         OSErr                    status;
  48.         int                        foundCount;
  49.         
  50.         if (AsyncSCSIPresent()) {
  51.             ClearMemory((Ptr) &pb, sizeof pb);
  52.             pb.scsiPBLength = sizeof (SCSIDriverPB);
  53.             pb.scsiCompletion = NULL;
  54.             pb.scsiFlags = 0;
  55.             pb.scsiFunctionCode = SCSILookupRefNumXref;
  56.             * ((long *) &pb.scsiDevice) = 0xFFFFFFFFL;
  57.             foundCount = 0;
  58.             do {
  59.                 status = SCSIAction((SCSI_PB *) &pb);
  60.                 if (status == noErr) {
  61.                     if (pb.scsiDevice.bus != 0xFF) {
  62.                         printf("Device ID [%d.%d.%d], %3d refNum\n",
  63.                             (int) pb.scsiDevice.bus,
  64.                             (int) pb.scsiDevice.targetID,
  65.                             (int) pb.scsiDevice.LUN,
  66.                             (int) pb.scsiDriver
  67.                         );
  68.                         ++foundCount;
  69.                     }
  70.                     pb.scsiDevice = pb.scsiNextDevice;
  71.                 }
  72.             }
  73.             while (pb.scsiDevice.bus != 0xFF);
  74.             switch (foundCount) {
  75.             case 0:        printf("No devices were registered\n");                break;
  76.             case 1:        printf("One device was registered\n");                break;
  77.             default:    printf("%d devices were regisered\n", foundCount);    break;
  78.             }
  79.         }
  80.         else {
  81.             printf("SCSI Manager 4.3 is not present on this machine\n");
  82.         }
  83. }
  84.  
  85.  
  86.